const fs = require('fs');
const path = require('path');

module.exports = () => {
  return async (ctx, next) => {
    if (ctx.path === '/') {
      // eslint-disable-next-line no-undef
      const indexHtmlPath = path.join(__dirname, '../public/index.html');
      const indexHtmlContent = fs.readFileSync(indexHtmlPath, 'utf8');
      ctx.type = 'html';
      ctx.body = indexHtmlContent;
      return;
    }
  await next();

  };
};